<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateOrdersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('orders', function (Blueprint $table) {
            $table->increments('id')->unsigned()->comment('订单表');
            $table->string('no')->unique()->comment('订单编号');
            $table->unsignedInteger('shop_id')->comment('店铺id');
            $table->unsignedInteger('user_id')->comment('用户id');
            $table->string('contact_name')->comment('联系人');
            $table->string('contact_phone')->comment('联系人电话');
            $table->unsignedInteger('goods_id')->nullable()->comment('商品id');
            $table->string('goods_type')->nullable()->comment('商品类型');
            $table->integer('schedule_id')->nullable()->comment('预定时间id');
            $table->decimal('total_amount')->comment('支付金额');
            $table->dateTime('paid_at')->nullable()->comment('支付时间');
            $table->string('refund_status')->default(\App\Models\Order::REFUND_STATUS_PENDING)->comment('退款状态');
            $table->boolean('refund_verify')->default(false)->comment('退款验证是否成功');
            $table->dateTime('refund_at')->nullable()->comment('退款时间');
            $table->string('status')->default(\App\Models\Order::STATUS_PENDING)->comment('订单状态');
            $table->boolean('closed')->default(false)->comment('订单是否关闭');
            $table->double('seller_distance', 10, 2)->nullable()->comment('商家距离订单约定地点距离');
            $table->double('user_distance', 10, 2)->nullable()->comment('用户距离订单约定地点距离');
            $table->text('remark')->nullable()->comment('备注');
            $table->softDeletes();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('orders');
    }
}
